package de.unimannheim.ki.tests;

import java.util.List;

import weka.associations.FPGrowth;
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;

import de.unimannheim.ki.algorithmn.LikeAssociationJoint;
import de.unimannheim.ki.algorithmn.LikeDisJoint;
import de.unimannheim.ki.algorithmn.NNAlgorithm;
import de.unimannheim.ki.algorithmn.Neighbour;
import de.unimannheim.ki.databaseentities.Musicuser;
import de.unimannheim.ki.usermanagement.DatabaseUserDAO;

public class SimpleAlgoTest2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		DatabaseUserDAO dao = DatabaseUserDAO.getDAO();
		List<Musicuser> allUsers = dao.getAllUsers();
		
		Musicuser testuser = dao.getUser("1346055375");

		 Instances data = null;
			try {
				 DataSource source = new DataSource("sample5.csv");
				 data = source.getDataSet();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		// setting class attribute
			
			 FPGrowth model = new FPGrowth();
			 model.setDelta(0.01);
		     model.setLowerBoundMinSupport(0.01);
		     model.setMinMetric(0.5);
		     
			 model.setFindAllRulesForSupportLevel(true);
			 model.setNumRulesToFind(10000);
			
			 try {
				model.buildAssociations(data);
				System.out.println(model.getAssociationRules().getNumRules()+"");
			 } catch ( Exception e) {
				 e.printStackTrace();
			 }
			 
			 System.out.println("Start NN Algorithm");
			
			 
		NNAlgorithm nn = new NNAlgorithm(new LikeAssociationJoint(model,dao));
		List<Neighbour> neighbours = nn.computeNeighbours(testuser);
		
		for (int i = 0; i < neighbours.size(); i++) {
			if(neighbours.get(i).getDistance() > 0.1) System.out.println(neighbours.get(i).toString());
		}

	}

}
